<template>
    <Modal
            width="800"
            v-model="visible"
            :title="title"
            :key="key"
    >
        <div style="width: 80%;padding-left: 10%;padding-right: 10%">
            <Form :label-width="130" ref="formValidate" :model="formValidate"
                  :rules="ruleValidate">
                <Form-item label="救助类型:" prop="assistancetype">
                    <c-dict-select v-model="formValidate.assistancetype" dictCode="assistancetype" :width="400"/>
                </Form-item>
                <Form-item label="业务类型:" prop="handletype">
                    <c-dict-select v-model="formValidate.handletype" dictCode="handletype" :width="400"/>
                </Form-item>
                <Form-item label="行权事项编码:" prop="orderid">
                    <Input v-model="formValidate.orderid" style="width: 400px"/>
                </Form-item>

                <Form-item label="流程xml:" prop="processxml">
                    <Input v-model="formValidate.processxml" type="textarea" :autosize="{minRows: 10,maxRows: 20}"
                           :disabled="disabled" style="width: 400px"/>
                </Form-item>
            </Form>
        </div>
        <div slot="footer">
            <Button @click="cancel">取消</Button>
            <template v-if="!disableSubmit">
                <Button type="primary" @click="ok">保存并解析</Button>
            </template>
        </div>
    </Modal>
</template>

<script>
    import {getAction, postAction} from '@/api/request'

    export default {
        data() {
            return {
                modal1: false,
                title: "",
                disabled: false,
                visible: false,
                disableSubmit: false,
                formValidate: {},
                key: "",
                ruleValidate: {
                    handletype: [
                        {required: true, message: '业务类型不能为空', trigger: 'blur'}
                    ],
                    assistancetype: [
                        {required: true, message: '救助类型不能为空', trigger: 'blur'}
                    ],
                    processxml: [
                        {required: true, message: '流程xml不能为空', trigger: 'blur'}
                    ],
                    orderid: [
                        {required: true, message: '行权orderid不能为空', trigger: 'blur'}
                    ]
                },
                url: "",
            }
        },
        methods: {
            add() {
                this.url = "/api/ac/subsistence/extActProcessService/insert";
                this.visible = true;
                this.disabled = false;
                this.formValidate = Object.assign({}, {});
            },
            ok() {
                var that = this;
                this.$refs['formValidate'].validate((valid) => {
                    if (valid) {
                        that.submitFrom();
                    }
                })
            },

            submitFrom() {
                var that = this;
                that.Loading = true;
                postAction(this.url, this.formValidate).then((res) => {
                    if (res.data.errcode != 0) {
                        this.$Message.error(res.data.errmsg);
                    } else {
                        this.$emit('ok');
                        this.visible = false;
                    }
                }).finally(() => {
                    that.Loading = false;
                });
            },
            cancel() {
                this.visible = false;
            },
            edit(row) {
                this.disabled = false;
                this.url = "/api/ac/subsistence/extActProcessService/update";
                this.visible = true
                this.formValidate = Object.assign({}, row);
            },
        }
    }
</script>

<style scoped>

</style>
